//
//  EmoticonCell.m
//  XinLang_OC
//
//  Created by Boss Lin on 16/5/16.
//  Copyright © 2016年 cheuhui. All rights reserved.
//

#import "EmoticonCell.h"
#import "Emoticon.h"

@interface EmoticonCell ()

@property(nonatomic,strong) UIButton *emoticonButton;

@end

@implementation EmoticonCell

- (void)setEmoticon:(Emoticon *)emoticon {
    _emoticon = emoticon;
    
    if (emoticon.pngPath) {
        // 设置表情图片
        //// 设置表情图片
        // contentsOfFile: 不会缓存,使用完就释放了
        // named: 一直缓存在内存中
        [self.emoticonButton setImage:[UIImage imageWithContentsOfFile:emoticon.pngPath] forState:UIControlStateNormal];
    } else {
        [self.emoticonButton setImage:nil forState:UIControlStateNormal];
    }
    
    // 设置emoji表情
    [self.emoticonButton setTitle:emoticon.emoji forState:UIControlStateNormal];
    
    
    // 如果是删除按钮,显示删除按钮图片
    if (emoticon.removeEmoticon) {
        [self.emoticonButton setImage:[UIImage imageNamed:@"compose_emotion_delete"] forState:UIControlStateNormal];
    }
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if ([super initWithCoder:aDecoder]) {
        [self prepareUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if ([super initWithFrame:frame]) {
        [self prepareUI];
    }
    return self;
}

- (void)prepareUI {
    // 添加子控件
    [self.contentView addSubview:self.emoticonButton];
    
    self.emoticonButton.frame = CGRectInset(self.bounds, 6, 6);
    
    self.emoticonButton.titleLabel.font = [UIFont systemFontOfSize:32];
    
    self.emoticonButton.userInteractionEnabled = NO;
}

- (UIButton *)emoticonButton {
    if (!_emoticonButton) {
        _emoticonButton = [UIButton new];
    }
    return _emoticonButton;
}

@end








